let userchart = echarts.init(document.getElementById("user"));
let changechart = echarts.init(document.getElementById("change"));
  showChart();
  function showChart() {
    $.ajax({
      url: '/chart',
      method: 'post',
      data: '',
      success: (res) => {
        if (res.error) {

          console.log(res.error);
        } else {
          let useroption = {
            title: {
              text: '管理人员数量统计表',
              // subtext: 'Fake Data',
              left: 'center',

            },
            tooltip: {
              trigger: 'item'
            },
            legend: {
              orient: 'vertical',
              left: 'left'
            },
            series: [
              {
                name: '管理人员统计表',
                type: 'pie',
                radius: '50%',
                data: [
                  { value: res.data[0].num, name: res.data[0].dep },
                  { value: res.data[1].num, name: res.data[1].dep },
                  { value: res.data[2].num, name: res.data[2].dep },
                  { value: res.data[3].num, name: res.data[3].dep },
                  { value: res.data[4].num, name: res.data[4].dep }
                ],
                emphasis: {
                  itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                  }
                }
              }
            ]
          }
          userchart.setOption(useroption)
          let changeoption = {
            title: {
              text: '管理人员变动统计表',

            },
            tooltip: {
              trigger: 'axis'
            },
            legend: {
              data: ['仓管部', '生产部', '运输部', '采购部', '销售部']
            },
            grid: {
              left: '3%',
              right: '4%',
              bottom: '3%',
              containLabel: true
            },
            toolbox: {
              feature: {
                saveAsImage: {}
              }
            },
            xAxis: {
              type: 'category',
              boundaryGap: false,
              data: ['2016', '2017', '2018', '2019', '2020', '2021', '2022']
            },
            yAxis: {
              type: 'value'
            },
            series: [
              {
                name: '仓管部',
                type: 'line',
                stack: 'Total',
                data: [1, 2, 4, 5, 6, 8, res.data[0].num]
              },
              {
                name: '生产部',
                type: 'line',
                stack: 'Total',
                data: [2, 2, 3, 5, 6, 7, 8, res.data[1].num]
              },
              {
                name: '运输部',
                type: 'line',
                stack: 'Total',
                data: [2, 2, 4, 5, 6, 8, 8, res.data[2].num]
              },
              {
                name: '采购部',
                type: 'line',
                stack: 'Total',
                data: [3, 2, 4, 5, 6, 8, 9, res.data[3].num]
              },
              {
                name: '销售部',
                type: 'line',
                stack: 'Total',
                data: [5, 6, 5, 8, 6, 8, 9, res.data[4].num]
              }
            ]
          };
          changechart.setOption(changeoption)
        }
      }
    })
  }
